
package com.neegix.log.exceptionLog.interfaces.controller;

import com.neegix.base.PageVO;
import com.neegix.cqrs.command.UniversalCommandBus;
import com.neegix.cqrs.query.UniversalQueryBus;
import com.neegix.log.exceptionLog.application.service.command.DeleteExceptionLogCommand;
import com.neegix.log.exceptionLog.application.service.query.GetExceptionLogDetailQuery;
import com.neegix.log.exceptionLog.application.service.query.GetPageExceptionLogQuery;
import com.neegix.log.exceptionLog.application.service.query.mapper.ExceptionLogQueryMapper;
import com.neegix.log.exceptionLog.interfaces.form.QueryExceptionLogForm;
import com.neegix.log.exceptionLog.interfaces.vo.ExceptionLogVO;
import com.neegix.inferfaces.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-12-19 15:04:54
  */

@RestController
@RequestMapping("/api/v1/exceptionLog")
public class ExceptionLogController {

     @Autowired
     private UniversalCommandBus commandBus;

     @Autowired
     private UniversalQueryBus queryBus;

    @PreAuthorize("hasAuthority('log:exceptionLog:list')")
    @GetMapping("/{currentPage}/{pageSize}")
    public Result<PageVO<ExceptionLogVO>> getExceptionLogs(@PathVariable("currentPage") Integer currentPage, @PathVariable("pageSize") Integer pageSize, @ModelAttribute QueryExceptionLogForm exceptionLogForm){
        if(exceptionLogForm == null) {
            exceptionLogForm = new QueryExceptionLogForm();
        }
        GetPageExceptionLogQuery getPageExceptionLogQuery = ExceptionLogQueryMapper.INSTANCE.covertToGetQuery(exceptionLogForm);
        getPageExceptionLogQuery.setCurrentPage(currentPage);
        getPageExceptionLogQuery.setPageSize(pageSize);
        PageVO<ExceptionLogVO> pageVO = queryBus.execute(getPageExceptionLogQuery);
        return Result.success("查询成功",pageVO);
    }

    @PreAuthorize("hasAuthority('log:exceptionLog:get')")
    @GetMapping("/{id}")
    public Result<ExceptionLogVO> getExceptionLogById(@PathVariable("id") Long id) {
        return Result.success("获取成功", queryBus.execute(new GetExceptionLogDetailQuery(id)));
    }

    @PreAuthorize("hasAuthority('log:exceptionLog:remove')")
    @DeleteMapping
    public Result<Void> removeExceptionLog(@RequestBody List<Long> ids){
        return Result.success("删除成功", commandBus.execute(new DeleteExceptionLogCommand(ids)));
    }
}